package com.spark.data

import android.support.annotation.LayoutRes
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.widget.ImageView
import android.widget.RelativeLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.spark.colliery.common.ext.gone
import com.spark.colliery.common.ext.isVisible
import com.spark.common.ext.sdf
import com.spark.data.model.BorrowListModel

class DateQrItemAdapter(@LayoutRes layoutRes: Int) : BaseQuickAdapter<BorrowListModel.ResultMap, BaseViewHolder>(layoutRes) {
    override fun convert(helper: BaseViewHolder?, item: BorrowListModel.ResultMap?) {
        helper?.apply {
            if (item == null) return
            //setText(R.id.tv_name, item.name)
            setText(R.id.tv_name, "2018安全生产标准试行办法")
            //setText(R.id.tv_state, item.returnDay)
            setText(R.id.tv_state, "3天后")
            //setText(R.id.tv_serial, "编号：${item.number}")
            setText(R.id.tv_serial, "编号：20-01-02")
            //setText(R.id.tv_regular, "规范：${item.stdname}")
            setText(R.id.tv_regular, "规范：试行办法")
            setText(R.id.tv_created, "创建：${sdf("yyyy-mm-dd").format(item.editionTime)}")
            //setText(R.id.tv_tags, "标签：${item.keysName}")
            setText(R.id.tv_tags, "标签：2018、安全、标准")
            val rlInfo = getView<RelativeLayout>(R.id.rl_info)
            rlInfo.gone(true)
            getView<ImageView>(R.id.iv_expand).setOnClickListener {
                val state = rlInfo.isVisible()
                rlInfo.gone(state)
            }

            val recyBooks = getView<RecyclerView>(R.id.recy_books)
            recyBooks.layoutManager = object : LinearLayoutManager(mContext) {
                override fun canScrollVertically(): Boolean {
                    return false
                }
            }
            val borrowBookAdapter = BorrowBookAdapter(R.layout.item_borrow_book)
            recyBooks.adapter = borrowBookAdapter
            borrowBookAdapter.addData(item.fileList)
            borrowBookAdapter.addData(mutableListOf(
                    BorrowListModel.ResultMap.File(filename = "2018安全标准试行办法"),
                    BorrowListModel.ResultMap.File(filename = "2018安全标准试行办法"),
                    BorrowListModel.ResultMap.File(filename = "2018安全标准试行办法"),
                    BorrowListModel.ResultMap.File(filename = "2018安全标准试行办法"),
                    BorrowListModel.ResultMap.File(filename = "2018安全标准试行办法"),
                    BorrowListModel.ResultMap.File(filename = "2018安全标准试行办法")
            ))

            getView<TextView>(R.id.tv_apply_detail).setOnClickListener {
                onItemChildClickListener?.onItemChildClick(this@DateQrItemAdapter, it, adapterPosition)
            }
        }
    }

}
